/**
 * Created with JetBrains WebStorm.
 * User: Fred_974
 * Date: 14/06/13
 * Time: 11:16
 * To change this template use File | Settings | File Templates.
 */
var connector = require('./connector');
var connection = connector.connection();
// We need our model


var persistHealth = function(health, callback){

    var post  = {name : health.name,
        min: health.min, max : health.max}

    if(userPlantation.id == null){

        connection.query('INSERT INTO health SET ?', post, function(err, result, fields){

            if (err) throw err; // if there is an error we throw it
            health.id = result.insertId;
            callback(health); // Callback basicaly it's the end of the controleur
        });

    }else{
        connection.query('update health SET ? where id = ?',[post,health.id], function(err, rows, fields){

            if (err) throw err; // if there is an error we throw it
            callback(rows[0]); // Callback basicaly it's the end of the controleur
        });

    }


};


var findAll = function(callback){

    connection.query('select * from health', function(err, rows, fields){

        if (err) throw err; // if there is an error we throw it

        callback(rows); // Callback basicaly it's the end of the controleur

    });
}


exports.persistHealth = persistHealth;
exports.findAll = findAll;